/*
 * File:   DictionaryTest.cpp
 * Author: Luis Aguirre
 *
 * Created on 26-07-2013, 01:13:02 PM
 */

#include "dictionarytest.h"
#include "ebook/dictionary.h"

CPPUNIT_TEST_SUITE_REGISTRATION(DictionaryTest);

DictionaryTest::DictionaryTest()
{
}

DictionaryTest::~DictionaryTest()
{
}

void DictionaryTest::setUp()
{
}

void DictionaryTest::tearDown()
{
}

void DictionaryTest::testLoadDictionaryGivenADictionary()
{
    const char* dicPath = "resources/dic.txt";
    Dictionary* dic = new Dictionary(dicPath);
    CPPUNIT_ASSERT(dic->words.size() == 6);
    CPPUNIT_ASSERT(dic->words.front() == "Sample");
    dic->words.pop_front();
    CPPUNIT_ASSERT(dic->words.front() == "word");
    dic->words.pop_front();
    CPPUNIT_ASSERT(dic->words.front() == "softWare");
    dic->words.pop_front();
    CPPUNIT_ASSERT(dic->words.front() == "Windows");
    dic->words.pop_front();
    CPPUNIT_ASSERT(dic->words.front() == "Linux");
    dic->words.pop_front();
    CPPUNIT_ASSERT(dic->words.front() == "MAIN");
}

void DictionaryTest::testLoadDictionaryGivenANonExistentFile()
{
    try
    {
        Dictionary* dic = new Dictionary("resources/something.txt");
        dic->words.pop_front();
        CPPUNIT_ASSERT(false);
    }
    catch(FileNotFoundExpcetion)
    {
        CPPUNIT_ASSERT(true);
    }
    
}

void DictionaryTest::testLoadDictionaryGivenANull()
{
    try
    {
        Dictionary* dic = new Dictionary(NULL);
        dic->words.pop_front();
        CPPUNIT_ASSERT(false);
    }
    catch(NullPathException)
    {
        CPPUNIT_ASSERT(true);
    }
}

